
// Copyright (C) Recursion Company. All rights reserved.

#include "stdafx.h"
#include "vol_user_app_info.h"

BOOL_P CVWnd_IPEdit::sCheckIPAddress (const TCHAR* szAddress, INT_P* anpIP)
{
    ASSERT_RW_ADR (anpIP, sizeof (INT_P) * 4);

    CMArray<INT> nary;
    if (SplitIntegers (szAddress, nary, '.') != 4)
        return FALSE;

	for (INT_P npIndex = 0; npIndex < 4; npIndex++)
	{
        const INT_P np = nary [npIndex];
        if (np < 0 || np > 255)
            return FALSE;

	    anpIP [npIndex] = np;
	}

    return TRUE;
}

BOOL CVWnd_IPEdit::CreateControl (CVolNativeWndCreateParam* pCreateParam)
{
	if (_CREATE_WND_BY_PARAM (pCreateParam) != NULL)
	{
        ModifyWndStyleEx (this, 0, pCreateParam->m_dwExStyle);

        INT_P anpIP [4];
        if (sCheckIPAddress (m_strIP.GetText (), anpIP))
            SetAddress (MAKEIPADDRESS (anpIP [0], anpIP [1], anpIP [2], anpIP [3]));
        else
            ClearAddress ();

        return TRUE;
	}

    return FALSE;
}

LRESULT CVWnd_IPEdit::OnSetFocus (UINT uNotifyCode, int nID, CWindow wndCtl)
{
    SendSetFocusNativeMessage (m_hWnd, m_pEventListener);
    return 0;
}

LRESULT CVWnd_IPEdit::OnKillFocus (UINT uNotifyCode, int nID, CWindow wndCtl)
{
	SendKillFocusNativeMessage (m_hWnd, m_pEventListener);
    return 0;
}

LRESULT CVWnd_IPEdit::OnChange (UINT uNotifyCode, int nID, CWindow wndCtl)
{
    if (m_pEventListener != NULL)
        m_pEventListener->OnChange ();
    return 0;
}
